import routerlist from "./routerconfig";
import {Suspense} from "react" // 路由切换时候的loading
import { Route, Routes, NavLink, Navigate,BrowserRouter } from 'react-router-dom'
let RouterView = ()=>{
    let renderRoute = (routerlist)=>{
        return routerlist.map((item,index)=>{
            return item.path ? <Route key={index} path={item.path} element={<item.element></item.element>}>
                {
                    item.children && renderRoute(item.children)
                }
            </Route>:
                               <Route key={index} path={item.from} element={<Navigate to={item.to}></Navigate>}> </Route>
        })
    }
    return <BrowserRouter>
                <Suspense fallback={<div>...loading</div>}>
                    <Routes>
                        {
                            renderRoute(routerlist)
                        }
                    </Routes>
                </Suspense>
           </BrowserRouter>
}
export default RouterView